//
//  PdfDetailViewController.m
//  Estate
//
//  Created by heyong on 16/8/22.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "PdfDetailViewController.h"
#import "MJPhotoBrowser.h"

@implementation PdfDetailViewController
- (WKWebView *)webView{
    if(!_webView){
        _webView=[[WKWebView alloc]initWithFrame:CGRectMake(0, 0, DEF_WIDTH(self.view),DEF_HEIGHT(self.view))];
    }
    return _webView;
}

- (UIImageView *)imageView{
    if(!_imageView){
        _imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT/3)];
        _imageView.center=self.view.center;
        _imageView.contentMode =  UIViewContentModeCenter;
        //        _imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        //        _imageView.clipsToBounds  = YES;
    }
    return _imageView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"附件详情";
    self.view.backgroundColor=[UIColor whiteColor];
    NSLog(@"pdf地址：%@",self.filePath);
    //加载pdf
    if([self.fileType isEqualToString:@"pdf"]){
        NSString *path= DEF_FILE_PDF_PATH;
        [self.webView loadFileURL:[NSURL fileURLWithPath:self.filePath] allowingReadAccessToURL:[NSURL fileURLWithPath:path]];
        [self.view addSubview:self.webView];
        //        self.webView.scalesPageToFit = YES;
        
    }
    //加载图片
    else
    {
        //        [self.view addSubview:self.imageView];
        //        self.imageView.image=[UIImage imageWithContentsOfFile:self.filePath];
        //        self.imageView.userInteractionEnabled=YES;
        //        UITapGestureRecognizer *pan=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImageView) ];
        //        [self.imageView addGestureRecognizer:pan];
        //        [self clickImageView];
    }
}
- (void)webView:(WKWebView *)webView
didFinishNavigation:(WKNavigation *)navigation
{
    UIView *v = webView;
    while (v) {
        v.backgroundColor = [UIColor whiteColor];
        v = [v.subviews firstObject];
    }
}
//点击图片放大显示
-(void)clickImageView{
    NSMutableArray *photos = [NSMutableArray array];
    
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.image = self.imageView.image;
    [photos addObject:photo];
    
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    browser.photos = photos;
    browser.showSaveBtn = NO;
    [browser show];
}
@end
